
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Abahe
 */
public class AskSoundScreen extends Canvas {

    MobileMonstersMIDlet midlet;
    private Image imgAskSound;
    private Image imgYesOff;
    private Image imgYesOn;
    private Image imgNoOff;
    private Image imgNoOn;
    private Image imgBackground;
    private int status = 1; //1 yes, 2 no
    private String statusKey = "";

    public AskSoundScreen(MobileMonstersMIDlet midlet) {
        setFullScreenMode(true);
        this.midlet = midlet;

        try {
            imgAskSound = Image.createImage("/ask_sound.png");
            imgYesOff = Image.createImage("/yes_off.png");
            imgYesOn = Image.createImage("/yes_on.png");
            imgNoOff = Image.createImage("/no_off.png");
            imgNoOn = Image.createImage("/no_on.png");
            imgBackground = Image.createImage("/base_background.png");
        } catch (IOException e) {
        }
    }

    protected void paint(Graphics g) {
        g.setColor(0x000077);
        //g.fillRect(0, 0, getWidth(), getHeight());

        g.drawImage(imgBackground, 0, 0, Graphics.TOP | Graphics.LEFT);
        
        g.drawImage(imgAskSound, (int) (0.5 * MobileMonstersMIDlet.WIDTH) - (imgAskSound.getWidth() / 2),
                (int) (0.5 * MobileMonstersMIDlet.HEIGHT), Graphics.TOP | Graphics.LEFT);

        if (status == 1) {
            g.drawImage(imgYesOn, 0, getHeight() - imgYesOn.getHeight(),
                    Graphics.TOP | Graphics.LEFT);
            g.drawImage(imgNoOff, getWidth() - imgNoOff.getWidth(),
                    getHeight() - imgYesOn.getHeight(),
                    Graphics.TOP | Graphics.LEFT);
        } else if (status == 2) {
            g.drawImage(imgYesOff, 0, getHeight() - imgYesOn.getHeight(),
                    Graphics.TOP | Graphics.LEFT);
            g.drawImage(imgNoOn, getWidth() - imgNoOff.getWidth(),
                    getHeight() - imgYesOn.getHeight(),
                    Graphics.TOP | Graphics.LEFT);
        }
    }

    protected void keyPressed(int keyCode) {

        statusKey = String.valueOf(keyCode);

        System.out.println("key : " + statusKey);

        //qwerty 
        if (keyCode == 103) {
            //midlet.exit();
            if(status==1){
                midlet.showMenuCanvas();
            }else{
                System.out.println("no");
            }
        }

        //portrait
        if (keyCode == -5) {
            //midlet.exit();
            if(status==1){
                midlet.showMenuCanvas();
            }else{
                System.out.println("no");
            }
        }
        if (keyCode == -4) { //left
            if (status == 1) {
                status = 2;
            } else {
                status = 1;
            }
        }
        if (keyCode == -3) { //right
            if (status == 1) {
                status = 2;
            } else {
                status = 1;
            }
        }

        repaint();
    }
}
